/*
    [0,0,1,1,1,2,2,3,3,4]
    ---
    i = 1
    count = 1
    ---
    i = 2
    nums[1] = nums[2]
    [0,1,1,1,1,2,2,3,3,4]
    ---
    i = 3
    count = 2
    ---
    i = 4
    count = 3
    ---
    i = 5
    nums[5 - 3] = nums[5] = 2
    [0,1,2,1,1,2,2,3,3,4]
    ---
    i = 6
    count = 4
    ---
    i = 7
    nums[7 - 4] = nums[7] = 3
    [0,1,2,3,1,2,2,3,3,4]
    ---
    i = 8
    count = 5
    ---
    i = 9
    nums[9 - 5] = nums[9] = 4
    [0,1,2,3,4,2,2,3,3,4]
 */
// 查看相等次数
var removeDuplicates1 = function(nums) {
    var count = 0;
    var n = nums.length;
    for (let i = 1; i < n; i++) {
        if (nums[i] !== nums[i-1]) {
            nums[i-count] = nums[i];
        } else {
            count++;
        }
    }
    return n - count;
};


console.log(removeDuplicates1([0,0,1,1,1,2,2,3,3,4]));


// [0,0,1,1,1,2,2,3,3,4]
// [0,1,1,1,1,2,2,3,3,4]
// [0,1,2,1,1,2,2,3,3,4]
// [0,1,2,3,3,2,2,3,3,4]
// [0,1,2,3,4,2,2,3,3,4]
// 查看不相等次数
var removeDuplicates2 = function (nums2) {
    if (nums2.length === 0) return 0;
    var i = 0;
    for (let j = 1; j < nums2.length; j++) {
        if (nums2[j] !== nums2[i]) {
            i++;
            nums2[i] = nums2[j];
        }
    }
    return i + 1;
};

console.log(removeDuplicates2([0,0,1,1,1,2,2,3,3,4]));
